import struct
from socket import *
# 接收端地址
ADDR = ('127.0.0.1', 8888)
if __name__ == "__main__":
    sock_fd = socket(AF_INET, SOCK_DGRAM)
    fmt = struct.Struct('i32sif')
    while True:
        input_student_info = input('请输入学生信息(id 姓名 年龄 分数):')
        if not input_student_info:
            break
        student_info_arr = input_student_info.split(" ")
        # 数据打包
        send_data = fmt.pack(int(student_info_arr[0]), student_info_arr[1].encode(), int(student_info_arr[2]),
                             float(student_info_arr[3]))
        sock_fd.sendto(send_data, ADDR)
    sock_fd.close()
